﻿
Imports ACompany.OrderProcessing.Presentation

Partial Class UserControls_Product_ProductList
    Inherits System.Web.UI.UserControl
    Implements IProductListView

    Private _ProductPresenter As ProductListPresenter

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        _ProductPresenter = New ProductListPresenter(Me)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _ProductPresenter.Display()
    End Sub

    Public WriteOnly Property Products() As System.Collections.Generic.List(Of ACompany.OrderProcessing.Model.Product) Implements ACompany.OrderProcessing.Presentation.IProductListView.Products
        Set(ByVal value As System.Collections.Generic.List(Of ACompany.OrderProcessing.Model.Product))
            Me.grdProducts.DataSource = value
            Me.grdProducts.DataBind()
        End Set
    End Property

    Protected Sub btnAddProduct_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddProduct.Click
        Response.Redirect("ProductDetail.aspx?Action=Detail")
    End Sub

    Protected Sub grdProducts_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdProducts.RowCommand
        Select Case e.CommandName.ToLower()

            Case "deleteproduct"

                _ProductPresenter.RemoveProductBy(New Guid(e.CommandArgument.ToString))

        End Select
    End Sub

    Public Sub ErrorMessage(ByVal Message As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.ErrorMessage
        If String.IsNullOrEmpty(Message) Then
            pnlError.Visible = False
        Else
            pnlError.Visible = True
        End If
        Me.litErrorMessage.Text = Replace(Message, Environment.NewLine, "<br/>")
    End Sub

    Public Sub InfoMessage(ByVal Message As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.InfoMessage
        If String.IsNullOrEmpty(Message) Then
            pnlInfo.Visible = False
        Else
            pnlInfo.Visible = True
        End If
        Me.litInfoMessage.Text = Replace(Message, Environment.NewLine, "<br/>")
    End Sub

    Public Sub ViewTitle(ByVal title As String) Implements ACompany.OrderProcessing.Presentation.IBaseView.ViewTitle

    End Sub
End Class
